package cn.com.jslh.boarpro.main.model;

import android.content.Context;

import com.blankj.utilcode.util.SPUtils;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import cn.com.jslh.boarpro.base.BaseApplication;
import cn.com.jslh.boarpro.base.mvp.BaseListModel;
import cn.com.jslh.boarpro.main.model.breeditems.BreedItem;
import cn.com.jslh.boarpro.main.model.breeditems.BreedItemFactory;
import cn.com.jslh.boarpro.util.JSONUtil;
import cn.com.jslh.boarpro.util.WebService;
import cn.com.jslh.boarpro.util.database.DataBaseUtil;

/**
 * 分娩记录
 * 作者：周洲 on 2017/7/26 11:02
 * <p>
 * 邮箱：double0zhou@126.com
 */

public class DeliveryRecordModelImpl extends BaseListModel {
//    public static String week ="#"; //周号
//    public static String fmdate="#";//分娩日期
    public static String zhusheid="";//猪舍
    public static String zzFlkType ="";//--仔猪群类型    1 种苗群  2 肉苗群
    public static String[] zzflktypes ={"种苗群","肉苗群"};
    public DeliveryRecordModelImpl(final Context context) {
        super(context);
        zhusheid="";
    }

    @Override
    public List<?> getDatas(String... params) {

        List<BreedItem> datas = new ArrayList<>();
        //分娩日期
//        datas.add(BreedItemFactory.createBreedItem(new BreedItem.DataTemplates("分娩日期", fmdate, "fenmianriqi", null, BreedItemFactory.DateBreedItem)));
        //猪舍
        datas.add(BreedItemFactory.createBreedItem(new BreedItem.DataTemplates("猪舍", "请选择猪舍", "zhushe", null, BreedItemFactory.ChoseBreedItem)));

        datas.add(BreedItemFactory.createBreedItem(new BreedItem.DataTemplates("仔猪群类型", "请选择类型", "zzFlkType", null, BreedItemFactory.ChoseBreedItem)));

        return datas;
    }

    /**
     * 获取数据库中存入的配种记录
     * @return
     */
    public List<JSONObject> getUIDatas() {
        JSONArray jsonArray = DataBaseUtil.GetData(context,"select * from WeanTable where zhuSheId = '"+DeliveryRecordModelImpl.zhusheid+"' order by _id desc");
        return JSONUtil.JsonArray2List(jsonArray);
    }

    /**
     * 提交记录数据
     * @param jsonStr
     * @param nListener
     */
    public void syncUpData(String jsonStr, WebService.NetSuccessListener nListener){
        new WebService.Builder(context,"importFenMianData","WSSowFacade")
                .showDialog(true)
                .addProperty("jsonString",jsonStr)
                .success(nListener)
                .post();
    }

    public void judgeZhuShe(String zhusheId, WebService.NetSuccessListener nListener){
        new WebService.Builder(context,"checkFMZhuShe","WSSowFacade")//exportMuZhuData //配种母猪
                .addProperty("zhuSheID",zhusheId)
                .addProperty("orgID", SPUtils.getInstance().getString(BaseApplication.FORGID))
                .addProperty("zzFlkType",-1)
                .success(nListener)
                .post();
    }

    public void getAsyncZhuShes(WebService.NetSuccessListener netSuccessListener){
        new WebService.Builder(context, "exportZhuShe", "WSZpigBaseDataFacade")
                .addProperty("lineID", SPUtils.getInstance().getString(BaseApplication.FLINEID))
                .addProperty("orgID", SPUtils.getInstance().getString(BaseApplication.FORGID))
                .addProperty("bizType","fmZhuSheByLine")
                .success(netSuccessListener).post();
    }
}
